﻿
using System.Runtime.InteropServices;

namespace LePcCtrlApp
{
    class KeyEventPacket
    {
        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        struct KeyEvent
        {
            public int Size;
            public byte CmdCode;
            public byte isKeyDown;//0 抬起 1 按下
            public int key;//键值
        };

        private KeyEvent m_KeyEvent;
        public KeyEventPacket()
        {
            m_KeyEvent = new KeyEvent();
            m_KeyEvent.Size = Marshal.SizeOf(m_KeyEvent);
            m_KeyEvent.CmdCode = 4;
        }
        public void MakeKeyEvent(byte bkeyDown, int keycode)
        {
            m_KeyEvent.isKeyDown = bkeyDown;
            m_KeyEvent.key = keycode;
        }
        public byte[] GetKeyEventPacket()
        {
            return Struct2Bytes.StructToBytes(m_KeyEvent);
        }
    }
}